﻿package {
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.utils.*;

	/**
	 * For post string information on stage
	 * @author wilson
	 */
	public class TextInfoBoard extends Sprite {

		public function TextInfoBoard() {
			init();
		}
		private function init():void {
			m_text = new TextField();
			m_text.multiline = true;
			addChild(m_text);

			this.addEventListener(Event.ADDED_TO_STAGE, bindToStage);
		}
		/**
		 * bind this text board on stage, invoked by ADDED_TO_STAGE event
		 * @parame
		 * @return
		 */
		private function bindToStage(e:Event = null):Boolean {
			if ( null == this.parent || null == this.stage ) {
				trace("havn't add to stage yet");
				return false;
			}
			m_fieldWidth = this.stage.stageWidth;
			m_fieldHeight = this.stage.stageHeight;

			m_text.width = m_fieldWidth;
			m_text.height = m_fieldHeight;
			return true;
		}
		/**
		 * paste a string on board
		 * @paramstr
		 */
		public function addShow(str:String):void {
			//trace(str);
			m_text.appendText( str );
			m_lineCount++;
			m_text.scrollV = m_lineCount;
		}
		private var m_text:TextField;
		private var m_fieldWidth:uint = 0;
		private var m_fieldHeight:uint = 0;
		private var m_lineCount:uint = 0;
	}

}